package org.example.controller;
import org.example.entity.Invitation;
import org.example.exception.*;
import org.example.service.ClanService;
import org.example.service.InvitationService;
import org.example.utils.R;
import org.example.vo.FamilyTree;
import org.example.vo.InvitationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/clan")
public class ClanController {
    @Autowired
    ClanService clanService;
    @Autowired
    InvitationService invitationService;

    @PostMapping("/combineFamily")
    public @ResponseBody R combineFamily(@RequestBody InvitationVo invitationVo) throws PermissionsDenyException, SenderIdException {
        invitationService.sendInvitation(invitationVo);
//        clanService.combineFamily(parentId);
        return R.ok().setData(null);
    }
    @RequestMapping("/findFamilyTree")
    public @ResponseBody R findFamilyTree() throws NoClanException {
        FamilyTree familyTree = clanService.findFamilyTree();
        return R.ok().setData(familyTree);
    }

//    自己主动退出某个家族,如果是管理者，解散家族
//    如果自己不是管理者,退出家族
    @RequestMapping("/disableClan")
    public @ResponseBody R quitFakeFamily() throws PermissionsDenyException, NoClanException {
        clanService.disableClan();
        return R.ok().setData(null);
    }
    @RequestMapping("/removeFamily")
    public @ResponseBody R removeFamily(int targetId) throws NoClanException, NoInThisClan, PermissionsDenyException {
        clanService.removeFamily(targetId);
        return R.ok().setData(null);
    }

    @RequestMapping("/transferLeader")
    public @ResponseBody R transferLeader(int targerId) throws NoInThisClan, PermissionsDenyException, ShouldNotBeStudent {
        clanService.transferLeader(targerId);
        return R.ok().setData(null);
    }

}
